/**
 * Created by IntelliJ IDEA.
 * User: alexander
 * Date: 21.09.11
 * Time: 13:45
 * To change this template use File | Settings | File Templates.
 */
package com.etc.buttons {
import flash.display.SimpleButton;
import flash.display.Sprite;

public class MySimpleButton extends SimpleButton {

    public function MySimpleButton( w: Number, h: Number, text:String, fs: Number = 16 ) {
        upState      = new ButtonDisplayState(w,h,text,0x433a34,0x345aa0, fs);
		overState      = new ButtonDisplayState(w,h,text,0xffffff,0x345aa0, fs);
        downState        = new ButtonDisplayState(w,h,text,0x433a34,0xd39dd4, fs);
        hitTestState   = new ButtonDisplayState(w,h,text,0xa279a2,0xd39dd4, fs);
        hitTestState.x = 0;
        hitTestState.y = 0;
        useHandCursor  = true;
    }
}

}

import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;

class ButtonDisplayState extends Sprite {
	private var bgColor:uint, tColor: uint;
	private var w: uint, h: uint;
	private var text: String;
	private var fs: Number;

	public function ButtonDisplayState(  w: uint, h: uint, text: String, tcolor: uint, bgColor:uint, fs: Number = 16 ) {
		this.bgColor = bgColor;
		this.tColor = tcolor;
		this.w = w;
		this.h = h;
		this.text = text;
		this.fs = fs;
		draw();
	}

	private function draw():void {

		graphics.beginFill(bgColor);
		graphics.drawRoundRect(-w/2 , -h/2 , w , h , 25, 25);
		graphics.endFill();

		var tf: TextField  = new TextField();
		var format:TextFormat = new TextFormat();
		format.font = "Arial";
		format.size = fs;
		format.bold = true;
		format.underline = false;
		format.align = TextFormatAlign.CENTER;
		format.color = tColor;
		tf.defaultTextFormat = format;
		tf.width = w;
		tf.height = h;
		tf.x = -w/2;
		tf.y = -10;
		addChild( tf );
		tf.text = text;
	}
}

